<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class crossref_create extends Page
{
       public $edPartDesc = null;
       public $Label7 = null;
       public $cmbInvType = null;
       public $cmbParts = null;
       public $Label3 = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $compid = null;
       public $JTDivManufacturer = null;
       public $btnAddManufacturer = null;
       public $edManufacturer = null;
       public $listManufacturer = null;
       public $btnDelManufacturer = null;
       public $JTSiteTheme1 = null;
       public $JTGroupBox1 = null;
       public $btnShowManufacturer = null;
       public $imgBack = null;
       public $hiddenParts = null;
       public $memoCommnents = null;
       public $cmbVend = null;
       public $cmbMnfr = null;
       public $Image1 = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $lblFullDescription = null;
       public $Label2 = null;
       public $lblDescription = null;
       function crossref_createJSLoad($sender, $params)
       {
       $this->clr_crs();
       ?>
       //Add your javascript code here

       <?php

       }

       function cmbInvTypeJSChange($sender, $params)
       {
       echo $this->cmbInvType->ajaxCall('cmbInvChange');
        ?>
        return(false);
        <?php
       }

       function btnDelManufacturerJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var mnfrIndex = document.getElementById('listManufacturer').selectedIndex;
       var mnfrValue = document.getElementById('listManufacturer')[mnfrIndex].value;
       var compider3 = document.getElementById('compid').value;
       AjaxMnfr3(mnfrValue,compider3);
       <?php

       }

       function btnAddManufacturerJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addmnfr = document.getElementById('edManufacturer').value;
       var compider = document.getElementById('compid').value;
       AjaxMnfr2(addmnfr,compider);
       document.crossref_create.edManufacturer.value = "";
       <?php

       }

       function btnShowManufacturerJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivManufacturer').Show();
       document.crossref_create.edManufacturer.value = "";
       <?php

       }


       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnCancelClick($sender, $params)
       {

        redirect('veh_parts_crossref_list.php?stock_id='.$this->hiddenParts->getValue());

       }


       function cmbInvChange($sender, $params)
       {

       $inventory_id = $this->cmbInvType->getItemIndex();
       $this->cmbParts->Clear();
       $this->cmbParts->AddItem('--Select--', null, null);
       $result_inv = mysql_query("select * from invstocks_tbl where company_id = '".$_SESSION['company_id']."' and type='".$inventory_id."'");

       while($row_inv = mysql_fetch_array($result_inv))
       {
            $this->cmbParts->AddItem($row_inv['stock_num'].'-'.$row_inv['description'], null, $row_inv['stock_id']);
       }

       }

       function clr_crs()
       {
       $this->memoCommnents->Text = '&nbsp';
       $this->cmbInvType->Clear();
       $this->cmbInvType->AddItem('--Select--', null, null);
       $this->cmbInvType->setItemIndex('--Select--', null, null);
       $result_type = mysql_query("select * from lookup_inventory_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbInvType->AddItem($row_type['value'], null, $row_type['value']);
        }

       $this->cmbVend->Clear();
       $this->cmbVend->AddItem('--Select--', null, null);
       $this->cmbVend->setItemIndex('--Select--', null, null);
       $result_vend = mysql_query("select * from vendor_tbl where company_id='".$_SESSION['company_id']."'");

       while($row_vend = mysql_fetch_array($result_vend))
       {
            $this->cmbVend->AddItem($row_vend['vendor_name'], null, $row_vend['vendor_name']);
       }

       $this->cmbMnfr->Clear();
       $this->cmbMnfr->AddItem('--Select--', null, null);
       $this->cmbMnfr->setItemIndex('--Select--', null, null);
       $result_mnfr = mysql_query("select * from lookup_inventory_tbl where company_id='".$_SESSION['company_id']."' AND category='manufacturers'");

        while($row_mnfr = mysql_fetch_array($result_mnfr))
        {
            $this->cmbMnfr->AddItem($row_mnfr['value'], null, $row_mnfr['value']);
        }

       $this->cmbParts->setItemIndex('--Select--', null, null);

       }

       function crossref_createCreate($sender, $params)
       {
       $this->clr_crs();

       $this->compid->Value = $_SESSION['company_id'];
       $stock = $_GET['stock_id'];
       $this->hiddenParts->setValue($stock);
       $this->cmbParts->Clear();
       $this->cmbParts->AddItem('--Select--', null, null);
       //$this->edPartName->Text='';
       //$this->edPartNum->Text='';

       $this->cmbParts->Clear();
       $this->cmbParts->AddItem('--Select--',null,'--Select--');
        $result_parts = mysql_query("select * from invstocks_tbl where company_id='".$_SESSION['company_id']."'");

        while($row_parts = mysql_fetch_array($result_parts))
        {
            $this->cmbParts->AddItem($row_parts['stock_num'].'-'.$row_parts['description'], null, $row_parts['stock_id']);
        }

       $this->edPartDesc->Text='';

       $this->cmbInvType->Clear();
       $this->cmbInvType->AddItem('--Select--', null, null);
        $result_type = mysql_query("select * from lookup_inventory_tbl where company_id = '".$_SESSION['company_id']."' AND category='types'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbInvType->AddItem($row_type['value'], null, $row_type['value']);
        }



       $this->cmbMnfr->Clear();
       $this->cmbMnfr->AddItem('--Select--', null, null);
        $result_mnfr = mysql_query("select * from lookup_inventory_tbl where company_id='".$_SESSION['company_id']."' AND category='manufacturers'");

        while($row_mnfr = mysql_fetch_array($result_mnfr))
        {
            $this->cmbMnfr->AddItem($row_mnfr['value'], null, $row_mnfr['value']);
        }

        //list manufacturer
        $this->listManufacturer->Clear();
        $result_m = mysql_query("select * from lookup_inventory_tbl where company_id='".$_SESSION['company_id']."' AND category='manufacturers'");

        while($row_m = mysql_fetch_array($result_m))
        {
            $this->listManufacturer->AddItem($row_m['value'], null, $row_m['value']);
        }

       $this->cmbVend->Clear();
       $this->cmbVend->AddItem('--Select--', null, null);
        $result_vend = mysql_query("select * from vendor_tbl where company_id='".$_SESSION['company_id']."'");

        while($row_vend = mysql_fetch_array($result_vend))
        {
            $this->cmbVend->AddItem($row_vend['vendor_name'], null, $row_vend['vendor_name']);
        }

       $this->imgBack->setLink('veh_parts_crossref_list.php?stock_id='.$this->hiddenParts->getValue());

       }



       function btnSubmitClick($sender, $params)
       {
       mysql_query("INSERT INTO veh_parts_crossref(stock_id,
       company_id,
       manufacturer,
       vendor,
       inv_type,
       part_description,
       comments)

       VALUES
       ('".$this->hiddenParts->getValue()."',
       '".$_SESSION['company_id']."',
       '".$this->cmbMnfr->getItemIndex()."',
       '".$this->cmbVend->getItemIndex()."',
       '".$this->cmbInvType->getItemIndex()."',
       '".$this->cmbParts->getItemIndex()."',
       '".$this->memoCommnents->Text."')") or die("INSERT CROSSREF - ".mysql_error());

       echo"<script language=javascript>
       var answer = confirm('Add another record?');
       if(answer)
       {
       window.location = 'veh_parts_crossref_create.php?stock_id=".$this->hiddenParts->getValue()."';
       }
       else
       {
       window.location = 'veh_parts_crossref_list.php?stock_id=".$this->hiddenParts->getValue()."';
       }
       </script>";

       //redirect('veh_parts_crossref_list.php?stock_id='.$this->hiddenParts->getValue());

       }

}

global $application;

global $crossref_create;

//Creates the form
$crossref_create=new crossref_create($application);

//Read from resource file
$crossref_create->loadResource(__FILE__);

//Shows the form
$crossref_create->show();

?>